﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.ServiceModel;
using BookClubIt.Processor;
using DTO = BookClubIt.DTO;
using System.Web.UI.HtmlControls;


namespace BookClubIt.UserControls
{
    public partial class LeaderBox : BaseUserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }

        private void BindData()
        {

            DTO.Members members = MemberProcessorInstance.GetBookClubLeadersById(CID);
            rptLeaderList.DataSource = members;
            rptLeaderList.DataBind();
        }

        protected void rptLeaderList_OnItemDataBound(object sender, RepeaterItemEventArgs e)
        {
       

            RepeaterItem item = e.Item; if (item.ItemType == ListItemType.AlternatingItem || item.ItemType == ListItemType.Item)
                {
                 DTO.Member member = e.Item.DataItem as DTO.Member;
                HyperLink lnkMemberLink = (HyperLink)item.FindControl("lnkMemberLink");
                Image imgUserAvatar = (Image)item.FindControl("imgUserAvatar");
                Label lblStatus = (Label)item.FindControl("lblStatus");
            
                imgUserAvatar.ImageUrl = "../avatars/" + member.AvatarURL;
                lnkMemberLink.NavigateUrl = "../member.aspx?uid=" + member.Id;
                lnkMemberLink.Text = member.Username;
                    if (BookClubProcessorInstance.IsAdmin(member.Id, CID))
                    {
                        lblStatus.Text = "Admin";

                    } else if(BookClubProcessorInstance.IsLeader(member.Id,CID)){
                        lblStatus.Text = "Leader";
                    }
                }

            }
        }

    }